<!--
 * @description  :零售户选择组件 
 * @descriptionDetail: 零售户选择组件
 * @copyright    : 浙江烟草
 * @author       : lcm
 * @create       : 2022-09-27 09:58:58
-->

<template>
  <view>
    <u-row gutter="16">
      <u-col span="12">
        <view class="title">
          <u-icon :label="client.companyName" size="30" name="../../static/check/licence.png" v-if="client.licNo"></u-icon>
          <u-icon :label="client.companyName" size="30" name="../../static/check/nolicence.png" v-else></u-icon>
        </view>
      </u-col>
      <u-col span="12">
        <view class="sub-title">
          {{ client.businessAddr }}
        </view>
      </u-col>
      <u-col span="12">
        <u-row class="sub-title">
          <u-col span="5">
            <u-icon :label="client.managerName" size="30" name="../../static/check/manager.png"></u-icon>
          </u-col>
          <u-col span="2"></u-col>
          <u-col span="5">
            <u-icon label="电话" size="20" name="../../static/check/phone.png" color="#2979ff" @click.native="handlerShowPhone"></u-icon>
          </u-col>
        </u-row>
      </u-col>
    </u-row>
  </view>
</template>
<script>
import checkService from "@/service/check/check.service"
export default {
  name: "ClientItem",
  props: {
    client: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      tels: [],
    }
  },
  watch: {
    client: {
      immediate: true,
      handler() {
        this.$forceUpdate();
      },
    },
  },
  methods: {
    // 显示联系电话
    handlerShowPhone(e) {
      if (this.tels.length > 0) {
        // 此处不能使用u-action-sheet，在u-swipe-action中使用时样式异常
        uni.showActionSheet({
          itemList: this.tels,
          itemColor: "#007aff",
          success: ({tapIndex,}) => this.doPhone(this.tels[tapIndex]),
        });
        return;
      }
      this.$u.loading("查询中...");
      checkService.retailerTels(this.client.retailerUuid).then(dr => {
        this.$u.hideLoading();
        if (dr.success) {
          let telDatas = dr.data;
          telDatas.forEach(t => {
            t.tel && this.tels.push(t.name + " " + t.tel);
          });
          uni.showActionSheet({
            itemList: this.tels,
            itemColor: "#007aff",
            success: ({tapIndex,}) => this.doPhone(this.tels[tapIndex]),
          });
        }
      });
      e.stopPropagation();
      e.preventDefault();
    },
    // 拨打电话
    doPhone(telStr) {
      let tel = telStr.substring(telStr.indexOf(" "));
      this.$deviceApi.makePhoneCall(tel);
    },
  },
}
</script>
<style lang="scss" scoped>
.title {
  font-size: 15px;
  color: #666;
  font-weight: 600;
  margin: 5px 10px;
}
.sub-title {
  color: #666;
  margin: 3px 10px;
}
</style>